package com.cnsuning.jobtool.jobtools.rdrs;

import org.apache.commons.io.FileUtils;
import org.junit.Before;
import org.junit.Test;

import java.io.File;
import java.io.IOException;
import java.util.HashMap;
import java.util.List;

public class CheckDelay {
    private HashMap<String,String> columnsMap = new HashMap<>();

    @Before
    public void init() throws IOException {
        File columsFile = new File("src\\main\\java\\com\\cnsuning\\jobtool\\jobtools\\rdrs\\colums.txt");
        List<String> columnsList = FileUtils.readLines(columsFile);
        for (int i = 0; i <columnsList.size(); i++) {
            columnsMap.put("@"+(i+1),columnsList.get(i));
        }
    }


    @Test
    public void readbinglog() throws IOException {
        File binglogFile = new File("src\\main\\java\\com\\cnsuning\\jobtool\\jobtools\\rdrs\\bin1_after.txt");
        File targetFile = new File("src\\main\\java\\com\\cnsuning\\jobtool\\jobtools\\rdrs\\bin1_after_result.txt");
        List<String> linesList =  FileUtils.readLines(binglogFile);
        String str = "";
        for (String line : linesList)
        {
            String[] split = line.split("=");
            if (split !=null && split.length > 1)
            {
                String columnIndex = split[0];
                String columnValue = split[1];
                String columnName = columnsMap.get(columnIndex);
                str += ", "+columnName + " = "+ columnValue;
            }
        }
        str = str.substring(1);
        FileUtils.writeStringToFile(targetFile,str,false);

    }
}
